<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>watch属性</title>
    <!-- 引用vue.js库 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <p v-for="(item,index) in userArr">
            ,,
        </p>
        <button @click="clear">清空</button>
    </div>
    <script>
        let vm = new Vue({
        el: '#app',
        data: {
            userArr: [{
                userId: 1,
                userName: '张三',
                userSex: '男'
            }, {
                userId: 2,
                userName: '李四',
                userSex: '女'
            }, {
                userId: 3,
                userName: '王五',
                userSex: '男'
            }]
        },
        methods: {
            clear() {
                // this.userArr.length = 0;
                // console.log(this.userArr.length);    //0
                 //使用Vue中提供的变异方法
                 this.userArr.splice(0,this.userArr.length);
            }
        }
    });
    </script>
    
</body>
</html>